package com.javaoop.couese;

import java.util.Arrays;

/**
 * 课程：JavaOOP ，山西应用科技学院信息工程学院计算机科学与技术专业 2201班
 *
 * @author by 2022010101张三
 * @user Administrator
 * @Date 2024/12/4 7:01
 * @Description 任务或用途 TODO: 画布类的定义及呈现
 */
public class Canvas {
    private final int h;
    private int w;
    private char c;
    private char[][] matrix;
    public Canvas(int h, int w, char c) {
        this.h = h;
        this.w = w;
        this.matrix=new char[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                this.matrix[i][j]=c;
            }
        }
    }
    public char[][] getMatrix() {
        return matrix;
    }
    public void setMatrix(char[][] matrix) {
        this.matrix = matrix;
    }

    public int getH() {
        return h;
    }

    public int getW() {
        return w;
    }

    @Override
    public String toString() {
        return "Canvas{" +
                "h=" + h +
                ", w=" + w +
                ", c=" + c +
                ", matrix=" + Arrays.toString(matrix) +
                '}';
    }

    public void view(){
        for(char[] r:this.matrix){
            for(char c:r){
                System.out.printf("%s",c);
            }
            System.out.println();
        }
    }
    public void draw(Point p){
        this.matrix[p.getY()][p.getX()]=p.getC();
    }
    public static void main(String[] args) {
        System.out.println("======= 画布 ========");
        Canvas cv=new Canvas(30,50,'.');
        Point p=new Point(20,20,'x');
        //p.x=0;  //私有成员自己的对象不可以直接访问
        cv.draw(p);
        cv.view();
        System.out.println(cv);
    }
}